<template>
  <view>
    
    <view v-if="cart.length>0" class="cart-container">
      <my-address></my-address>
      <!-- 标题区域 -->
      <view class="title-box">
        <uni-icons type="shop" size="18"></uni-icons>
        <text> 购物车</text>
      </view>

      <!-- 商品区域 -->
      <block class="cart-list-item" v-for="(goods,index) in cart" :key="index">
        <uni-swipe-action>
          <uni-swipe-action-item :disabled="false" :right-options="options" @click="deleteGoods(goods.goods_id)">
            <my-goods :goods="goods" :showRadio="true" :show-button="true" @number-change="numChangeHandle"
              @radio-change="radioChangeHandle"></my-goods>
          </uni-swipe-action-item>
        </uni-swipe-action>
      </block>

    </view>
  <my-settle v-if="cart.length>0" ></my-settle>
  
  <view class="empty-cart">
    <image src="../../static/cart_empty@2x.png" v-if="cart.length<=0"></image>
    <text>购物车空空如也~</text>
  </view>
  </view>



</template>

<script>
  import tabbarNumber from "@/maxins/tabbar.js"
  import {
    mapState,
    mapMutations,
    mapGetters
  } from 'Vuex'
  export default {
    mixins: [tabbarNumber],
    computed: {},
    computed: {
      ...mapState('m_cart', ['cart']),
    },
    data() {
      return {
        options: [{
          text: '删除',
          style: {
            backgroundColor: '#dd524d'
          }
        }]
      }
    },
    onShow() {

    },
    methods: {
      ...mapMutations('m_cart', ['updateGoodsState', 'updateGoodsCount', 'deleteByGoodsId']),
      radioChangeHandle(e) {
        this.updateGoodsState(e)
      },
      numChangeHandle(e) {
        this.updateGoodsCount(e)
      },
      deleteGoods(id) {

        this.deleteByGoodsId(id)
      }
    }

  }
</script>

<style lang="scss">
  .cart-container{
    padding-bottom: 50px;
  }
  .title-box {
    height: 40px;
    display: flex;
    align-items: center;
    padding-left: 5px;
    border-bottom: 2px solid #efefef;

    text {
      margin-left: 8px;
    }
  }
  .empty-cart{
   padding-top: 150px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    image{
     
   
      width: 90px;
      height: 90px;
    }
    text{
      margin-top: 15px;
      font-size: 16;
      color:gray;
    }
  }
</style>